//
//  SearchViewController.m
//  TestAge2016(第六组)
//
//  Created by student on 16/4/11.
//  Copyright © 2016年 wk. All rights reserved.
//

#import "SearchViewController.h"

#import "NetManager.h"

#import <UIImageView+WebCache.h>

@interface SearchViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIView *rightView;
@property (weak, nonatomic) IBOutlet UIView *bottonView;


@end

@implementation SearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.rightView.layer.shadowOffset = CGSizeMake(5, 5);
    self.rightView.layer.shadowColor = [UIColor blackColor].CGColor;
    self.rightView.layer.shadowOpacity = 0.8;
    
    self.bottonView.layer.shadowOffset = CGSizeMake(5, 5);
    self.bottonView.layer.shadowColor = [UIColor blackColor].CGColor;
    self.bottonView.layer.shadowOpacity = 0.8;
    
    self.nameTextField.delegate = self;
    
    //请求图片
    [self requestPhotoList];
}


- (void)requestPhotoList
{
    
    [NetManager searchImagesByName:self.nameTextField.text successBlock:^(NSArray *imgList) {
        // 把图片显示到scrollview上
        for (int i = 0; i<imgList.count; i++)
        {
            NSString *urlStr = imgList[i];
            UIImageView *imgView = [[UIImageView alloc]init];
            imgView.frame = CGRectMake(i*200, 0, 200, 200);
            [self.scrollView addSubview:imgView];
            
            //加载图片
            [imgView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"placeholder"]];
            
            
        }
        
        self.scrollView.contentSize = CGSizeMake(imgList.count*200, 200);
        
    } failBlock:^(NSError *error) {
        
    }];
    
}

- (IBAction)goSettings:(id)sender {
}
- (IBAction)useThisPhoto:(id)sender {
}
- (IBAction)useOwnPhoto:(id)sender {
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    NSLog(@"输入了:%@",textField.text);
    
    [self requestPhotoList];
    
    return YES;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
